<template>
    <el-button type="success" plain icon="Download" @click="declareAll"
    >一键申报</el-button>
  <el-tooltip class="item" effect="dark" content="刷新" placement="top">
    <el-button circle icon="Refresh" @click="update" />
  </el-tooltip>
  <el-table
    @selection-change="selectChange"
    :data="WaitAssessorList"
    style="width: 90%;border-radius: 8px; margin: 20px auto;box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);"
    size="large"
    :header-cell-style="{
      background: '#337ecc !important',
      color: '#ffffff',
      border: 'none !important',
      textAlign: 'center',
    }"
    :cell-style="{ textAlign: 'center' }"
  >
    <el-table-column type="selection" width="55" :selection="selection" />
    <el-table-column prop="empName" label="员工姓名" width="150">
      <template #default="scope">
        <el-tooltip content="详情" placement="top-start" effect="light">
          <a style="text-decoration: none; color: black">
            {{ scope.row.empName }}
          </a>
        </el-tooltip>
      </template>
    </el-table-column>
    <el-table-column prop="position" label="岗位" width="180"></el-table-column>
    <el-table-column prop="deptName" label="所属单元" width="120" />
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="success" @click="onShowClick(scope.$index, scope.row)"
          >详情</el-button
        >
        <el-button @click="handleDeclare(scope.$index, scope.row)"
          >申报</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>


<script setup>
import { ref, onMounted, onBeforeMount, reactive } from "vue";
import { Timer } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import { getWageTask, updateWageEmpFlow,updateWageEmpFlowAll } from "@/api/task";
import { ElMessage } from 'element-plus'

const router = useRouter();
const WaitAssessorList = ref([]);
let empId = JSON.parse(localStorage.getItem("userInfo")).id;
let assessorId = JSON.parse(localStorage.getItem("userInfo")).id;
onBeforeMount(() => {
  getWageTask({ empId }).then((data) => {
    WaitAssessorList.value = data.data;
  });
});

const selection=ref([])
const selectChange = (select) => {
  selection.value = select;
};
const declareAll=()=>{
	var select = []
	for(var i = 0 ; i < selection.value.length;i++){
		select.push(selection.value[i])
	}
	
	
  updateWageEmpFlowAll({select,assessorId}).then(data=>{
    if (data.code == 200) {
      ElMessage({
        message: "申报成功",
        type: "success",
      });
      update()
    } 
    else {
      ElMessage.error("申报失败");
    }
  })
}

const onShowClick = (index, row) => {
  router.push({
    path: "/performDeclare/detail",
    query: row,
  });
};

const handleDeclare = (index, row) => {
  let positionId = row.positionId;
  let empId = row.empId;
  updateWageEmpFlow({assessorId, empId, positionId }).then((data) => {
    if (data.code == 200) {
      ElMessage({
        message: "申报成功",
        type: "success",
      });
      update()
    } 
    else {
      ElMessage.error("申报失败");
    }
  });
};

const update = () => {
  getWageTask({ empId }).then((data) => {
    if (data.code == 200) {
      ElMessage({
        message: "更新成功",
        type: "success",
      });
      WaitAssessorList.value = data.data;
    } 
    else {
      ElMessage.error("更新失败");
    }
  });
};
</script>

<style lang="scss" scoped>

::v-deep .el-step__head.is-process {
  color: rgb(52, 158, 250);
  border-color: rgb(52, 158, 250);
}
::v-deep .el-step__title.is-process {
    font-weight: bold;
    color: rgb(52, 158, 250);
}
::v-deep .el-step__description.is-process {
    color: rgb(52, 158, 250);
}
</style>
